MariaDB and MySQL Common Table Expressions and Window Functions Revealed by Daniel Bartholomew

MariaDB and MySQL Common Table Expressions and Window Functions Revealed by Daniel Bartholomew

Author:Daniel Bartholomew
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


NTILE

The syntax for the NTILE function is:

NTILE (<ntile_expression>) OVER (

[ <partition_definition> ]

[ <order_definition> ]

)

This function returns an integer indicating the group a certain row is in. The number of groups is specified by the <ntile_expression> part, and the numbering starts at 1. Ordered rows in the partition are divided into the specified number of groups, with each group being as equal in size to the other groups as possible.

For example, when using NTILE(2) on the values '1,2,2,3,4' the results would be:

+-------+----------+

| value | ntile(2) |

+-------+----------+

| 1 | 1 |

| 2 | 1 |

| 2 | 1 |

| 3 | 2 |

| 4 | 2 |

+-------+----------+



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.